<template>
  <el-table :data="tableData" style="width: 100%">
<!--  property属性    prop设置当前列显示的数据来自于数组中对象的xxx属性  -->
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
  </el-table>
  <h1>员工列表</h1>
  <el-table :data="arr">
    <el-table-column type="index" label="编号" width="80px"></el-table-column>
    <el-table-column prop="name" label="名字"></el-table-column>
    <el-table-column prop="salary" label="工资"></el-table-column>
    <el-table-column prop="job" label="工作"></el-table-column>

    <el-table-column label="操作">
<!--   自定义列必须添加下面的template标签   -->
      <template #default="scope">
<!--     scope.$index得到当前行的下标  scope.row得到当前行对应的对象 -->
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
const arr = ref([{name:"张三",salary:3000,job:"销售"},
  {name:"李四",salary:4000,job:"人事"}]);
const del=(i,emp)=>{
  if (confirm("您确认删除"+emp.name+"吗?")){
    arr.value.splice(i,1);
  }
}

const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>
